package haust;

import static org.lwjgl.opengl.GL11.*;
import java.util.ArrayList;
import org.lwjgl.input.Keyboard;

public class ModelContainer {
	private String modelName;
	public ArrayList<Float> coords;
	public ArrayList<Float> texcoords;
	public ArrayList<Float> normals;
	public ArrayList<Integer> indices;
	
	/**
	 * 
	 * @param name
	 * @param coords
	 * @param texCords
	 * @param normals
	 * @param indices
	 */
	public ModelContainer(String name, ArrayList<Float> coords, ArrayList<Float> texCords, ArrayList<Float> normals, ArrayList<Integer> indices){
		this.setModelName(name);
		this.coords=coords;
		this.texcoords=texCords;
		this.normals =normals;
		this.indices=indices;	
	}

	/**
	 * 
	 */
	public void render()
	{	
	    glBegin(GL_QUADS);
	    for( int i = 0; i < indices.size(); ++i )
	    {
	    	int index = indices.get(i);
	    	glTexCoord2f(texcoords.get(index*2), texcoords.get(index*2+1));
	    	index *= 3;
	    	glNormal3f(normals.get(index), normals.get(index+1), normals.get(index+2));
	    	glVertex3f( coords.get(index), coords.get(index+1), coords.get(index+2));	    	
	    }
	    glEnd();
	}
	
	/**
	 * Normal = -Normal
	 */
	public void flipNormals()
	{
		for( int i = 0; i < normals.size(); ++i )
		{
			normals.set(i, -normals.get(i));
		}
	}
	
	/**
	 * Swaps the Y and Z values for the model.
	 * Useful for models that utilize the Z axis as the up axis.
	 */
	public void flipYZ()
	{
		for( int i = 0; i < coords.size(); i+=3 )
		{
			float temp = coords.get(i+1);
			coords.set(i+1, coords.get(i+2));
			coords.set(i+2, temp);
		}
	}
	

	/**
	 * 
	 * @param modelName
	 */
	public void setModelName(String modelName) {
		this.modelName = modelName;
	}


	/**
	 * 
	 * @return
	 */
	public String getModelName() {
		return modelName;
	}
}
